<?php

namespace Admin\Controller;

class ArticleController extends CommonController
{
    // 查询列表
    public function lists()
    {
        $key       = I('request.key', '', 'trim');
        $audit     = I('request.audit', '', 'trim');
        $excellent = I('request.excellent', '', 'trim');
        $sort      = 'id DESC';

        if ($key) {
            $key_type = I('request.key_type', 0, 'intval');
            if ($key_type == '1') {
                $map['title'] = array('like', '%' . $key . '%');
            }
            if ($key_type == '2') {
                $map['content'] = array('like', '%' . $key . '%');
            }
            if ($key_type == '3') {
                $map['uid'] = intval($key);
            }
        }
        if ($audit <> '') {
            $map['audit'] = intval($audit);
        }
        if ($excellent <> '') {
            $map['excellent'] = intval($excellent);
        }

        $list = D('Article')->get_list($map, true, $sort, 10, true);

        $this->assign('lists', $list);

        $this->display();
    }

    // 修改审核
    public function audit()
    {
        $ids   = I('request.id');
        $audit = I('request.audit', '0', 'intval');

        $ids = is_array($ids) ? implode(",", $ids) : $ids;
        if ($ids && is_match_ids($ids)) {
            D('Article')->article_audit($audit, $ids);
            $this->success("设置成功！");
        } else {
            $this->error('请选择项目！');
        }
    }

    // 修改文章属性
    public function exc()
    {
        $ids       = I('request.id');
        $excellent = I('request.excellent', '0', 'intval');

        $ids = is_array($ids) ? implode(",", $ids) : $ids;
        if ($ids && preg_match("/^(\d{1,10},)*(\d{1,10})$/", $ids)) {
            D('Article')->article_excellent($excellent, $ids);
            $this->success("设置成功！");
        } else {
            $this->error('请选择项目！');
        }
    }

    // 删除文章
    public function delete()
    {
        $ids = I('request.id');

        $ids = is_array($ids) ? implode(",", $ids) : $ids;
        if ($ids && preg_match("/^(\d{1,10},)*(\d{1,10})$/", $ids)) {
            D("Article")->del_article($ids);
            $this->success("成功删除");
        } else {
            $this->error('请选择要删除的信息！');
        }
    }
}